package com.geping.etl.utils.common.commonsql;

import com.geping.etl.common.entity.Sys_UserAndOrgDepartment;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: wangzd
 * @Date: 2020/7/2
 */
public class CommonParam {

    public static List<ParamUtil> getParams(Sys_UserAndOrgDepartment sys_user, String isDept, String startDate,
                                            String endDate, String name, String reqid, String pid, String checkState) {
        List<ParamUtil> paramUtils = new ArrayList<>();
        paramUtils.add(new ParamUtil("orgid", MatchType.equal, sys_user.getOrgid()));

        if ("Y".equals(isDept)) {
            paramUtils.add(new ParamUtil("deptid", MatchType.equal, sys_user.getDepartid()));
        }
        if (StringUtils.isNotBlank(startDate)) {
            paramUtils.add(new ParamUtil("uploadts", MatchType.ge, startDate+" 00:00:00"));
        }
        if (StringUtils.isNotBlank(endDate)) {
            paramUtils.add(new ParamUtil("uploadts", MatchType.le, endDate+" 24:00:00"));
        }
        if (StringUtils.isNotBlank(name)) {
            paramUtils.add(new ParamUtil("name", MatchType.like, "%" + name.trim() + "%"));
        }
        if (StringUtils.isNotBlank(reqid)) {
            paramUtils.add(new ParamUtil("reqid", MatchType.like, "%" + reqid.trim() + "%"));
        }
        if (StringUtils.isNotBlank(pid)) {
            paramUtils.add(new ParamUtil("pid", MatchType.like, "%" + pid + "%"));
        }
        if (StringUtils.isNotBlank(checkState)) {
            paramUtils.add(new ParamUtil("checkstatus", MatchType.equal, checkState));
        }

        return paramUtils;
    }


}
